// 请用原生js语法书写
// 依赖layui表单提交

window.onload = function () {
    function IsPC() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break
            }
        }
        return flag
    }

    const userEqt = IsPC() ? 1 : 0
// console.log(userEqt)
    let nowUrl = window.location.href;
    let nowIp = returnCitySN["cip"];
    layui.use(['layer', 'form'], function () {
        var layer = layui.layer, form = layui.form;
        form.render();
        form.verify({
            username: val => {
                if (val.length > 1000) {
                    return "请输入正确的姓名"
                }
            }, address: value => {
                if (value.length > 1000) {
                    return "请输入正确的地区"
                }
            }
        });

        form.on('submit(go)', data => {
            var goForm = data.field;
            // console.log(goForm)
            let {username, phone, address} = goForm;
            // console.log(username)
            // console.log(phone)
            // console.log(address)
            // console.log(nowIp);
            axios.post("http://www.zhou-yuanwai.com/leave/insert.do?name=" + username + "&url=" + nowUrl + "&tell=" + phone + "&category=1&ip=" + nowIp + "&description=" + address + "&hasComputer=" + userEqt).then(res => {
                // console.log(res);
                if (res.data) {
                    layer.msg("发送成功，我们会尽快与您联系")

                    // 表单提交后设置所有输入框为空
                    let inps = document.querySelectorAll("input");
                    // console.log(inps)
                    inps.forEach(item => {
                        item.value = ""
                    })

                    // 判断是否有id为c-brn的按钮  在联系我们页面  若有，则改变样式  若无，则不操作
                    if (document.getElementById("c-btn")) {
                        // document.getElementById("c-btn").style.backgroundColor = "#e9493f"
                        document.getElementById("c-btn").style.backgroundColor = "rgb(244,157,22)"
                        document.getElementById("c-btn").innerText = "您已提交"
                    } else {
                        console.log("么得")
                    }
                }

            }).catch(err => {
                layer.msg("错误，请再次提交")
            });
            return false
        })
    });

//一般直接写在一个js文件中
    layui.use(['layer', 'form', "element"], function () {
        var layer = layui.layer
            , form = layui.form
            , element = layui.element;


    });

    var mySwiper = new Swiper('.my-banner', {
        autoplay: true,
        loop: true, // 循环模式选项

        // 如果需要滚动条
        scrollbar: {
            el: '.swiper-scrollbar',
        },
    });

    var mySwiper2 = new Swiper('.join-banner', {
        autoplay: true,
        slidesPerView: 3,
        centeredSlides: true,
        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });

    var mySwiper3 = new Swiper('.news-banner', {
        autoplay: true,
        slidesPerView: 3,
        slidesPerGroup: 3,
        centeredSlides: false,
        // 如果需要前进后退按钮
        navigation: {
            nextEl: '.swiper-button-next1',
            prevEl: '.swiper-button-prev1',
        },
    })

    $(".left-box").on("click", "li", function () {
        $(this).addClass("pn-active").siblings().removeClass("pn-active")
        const _thi_index = Number($(this).attr("data-index"))
        switch (_thi_index) {
            case 1:
                $(".left-box").css('background-image', 'url("../images/index/nav11.png")');
                $(".right-nav>li").eq(_thi_index - 1).fadeIn(300).siblings().fadeOut(1)
                // console.log($(".right-nav>li").eq(_thi_index-1))
                break;
            case 2:
                $(".left-box").css('background-image', 'url("../images/index/nav21.png")');
                $(".right-nav>li").eq(_thi_index - 1).fadeIn(300).siblings().fadeOut(1)
                // console.log($(".right-nav>li").eq(_thi_index-1))
                $("")
                break;
            case 3:
                $(".left-box").css('background-image', 'url("../images/index/nav31.png")');
                $(".right-nav>li").eq(_thi_index - 1).fadeIn(300).siblings().fadeOut(1)
                // console.log($(".right-nav>li").eq(_thi_index-1))
                break;
        }
    })
    $(".right-nav").on("mouseenter", "li", function (event) {
        event.stopPropagation();
        // console.log($(this))
        $(this).find("p").fadeIn(500)
    })
    $(".right-nav").on("mouseleave", "li", function (event) {
        // console.log($(this))
        $(this).find("p").fadeOut(500)
    })

}
